"<template>
	<table-layout
		:header-cell-style="{ color: '#000' }"
		show-summary
		:summary-method="getSummaries"
		:fetch-list="wmsWarehouseInventory"
		:query-form="props.queryForm"
		border
		ref="dataTableRef"
	>
		<template v-slot:tableLayout>
			<el-table-column
				v-for="(col, ind) in props.thList"
				:key="ind"
				:label="col.name"
				:prop="col.prop"
				:fixed="col.fixed ? col.fixed : false"
				:min-width="col.width ? col.width : '140'"
				:sortable="col.sortable"
			>
				<!-- th header -->
				<template #header>
					<div v-if="col.tooltip" style="display: flex; align-items: center">
						{{ col.name }}
						<el-tooltip effect="dark" :content="col.tooltip" placement="top">
							<el-icon><InfoFilled /></el-icon>
						</el-tooltip>
					</div>
					<span v-else>{{ col.name }}</span>
				</template>
				<template v-slot="scope">
					<template v-if="col.name === '仓库'">
						<div>
							{{ scope.row[col.prop] }}
						</div>
						<template v-for="item in state.typeList">
							<el-tag style="margin-top: 12px" :key="item.id" v-if="item.id === scope.row.whType" :type="item.type">
								{{ item.label }}
							</el-tag>
						</template>
					</template>
					<template v-if="col.name === '货值' || col.name === '采购成本' || col.name === '到库成本'">
						<div v-if="scope.row[col.prop]">{{ '￥' + scope.row[col.prop] }}</div>
					</template>
					<template v-if="col.name === '废品量'">
						<el-text class="mx-1" type="warning">{{ scope.row[col.prop] }}</el-text>
					</template>
				</template>
			</el-table-column>
		</template>
	</table-layout>
</template>
<script setup lang="tsx" name="whsList">
import { wmsWarehouseInventory } from '/@/api/inventory/index';
const props = defineProps({
	queryForm: {
		type: Object,
		default: () => {
			return {};
		},
	},
	thList: {
		type: Array,
		default: () => {
			return [];
		},
	},
});
const state = reactive({
	typeList: [
		{ type: 'danger', id: '1', label: '供应商仓' },
		{ type: 'primary', id: '2', label: '自营仓' },
		{ type: 'success', id: '3', label: '三方仓' },
		{ type: 'success', id: '4', label: 'FBA仓' },
	],
});
const toRefresh = (v) => {
	dataTableRef?.value.refresh(v);
};
const dataTableRef = ref();
const getSummaries = (param: SummaryMethodProps) => {
	const { columns, data } = param;
	const sums: string[] = [];
	columns.forEach((column, index) => {
		if (column.property !== 'goodsValue' && column.property !== 'purchaseCost' && column.property !== 'toWhCost') {
			const values = data.map((item) => Number(item[column.property]));
			if (!values.every((value) => Number.isNaN(value))) {
				sums[index] = `${values.reduce((prev, curr) => {
					let value = Number(curr);
					if (!Number.isNaN(value)) {
						return prev + curr;
					} else {
						return prev;
					}
				}, 0)}`;
			} else {
				sums[index] = '';
			}
		}
	});
	// 单独处理
	sums[0] = '当前页合计';
	return sums;
};

defineExpose({
	toRefresh,
});
</script>
<style lang="scss" scoped>
</style>
